package main

import (
	"bytes"
	"fmt"
	"github.com/sirupsen/logrus"
)

var EventLog *logrus.Logger

type MyFormatter struct {
}

func (m *MyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
	var b *bytes.Buffer
	if entry.Buffer != nil {
		b = entry.Buffer
	} else {
		b = &bytes.Buffer{}
	}

	timestamp := entry.Time.Format("2006-01-02 15:04:05")
	var newLog string
	newLog = fmt.Sprintf("[%s] [%s] %s\n", timestamp, entry.Level, entry.Message)

	b.WriteString(newLog)
	return b.Bytes(), nil
}

func main2() {
	//logrus.SetFormatter(&MyFormatter{})
	//EventLog = logrus.New()
	//EventLog.SetFormatter(new(MyFormatter))
	//EventLog.SetLevel(logrus.ErrorLevel | logrus.InfoLevel | logrus.DebugLevel | logrus.WarnLevel)
	////EventLog.WithField("name", "ball").WithField("say", "hi").Error("info log", "traceId:", "1234567890")
	//
	//go func() {
	//	EventLog.WithField("name", "ball").WithField("say", "hi").Error("协程info log", "traceId:", "9876543210")
	//}()

	requestLogger := logrus.WithField("request_id", "user_ip")
	requestLogger.Info("something happened on that request")
	requestLogger.Warn("something not great happened")
}
